/**
 * 
 */
package com.ctn.task.condition.impl;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicBoolean;

import com.ctn.task.condition.TaskCondition;

/**
 * 常规条件
 * @author Zale
 *
 */
public abstract class BaseCondition implements TaskCondition,Serializable {
	private static final long serialVersionUID = 1740896477401746314L;
	private AtomicBoolean isExecute;
	
	
	public AtomicBoolean getIsExecute() {
		return isExecute;
	}


	public void setIsExecute(AtomicBoolean isExecute) {
		this.isExecute = isExecute;
	}


	@Override
	public boolean canExecute() {
		boolean result = false;
		if(isExecute.compareAndSet(false, true)){
			result = checkCondition();
			if(!result){
				isExecute.set(false);
			}
		}
		return false;
	}


	protected abstract boolean checkCondition();
	
	
}
